package com.example.fund;

import java.util.List;
import java.util.Map;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class FundListViewAdapter  extends BaseAdapter{
    private LayoutInflater mInflater;
    private List<Map<String, Object>> fundList;//基金列表
    private CallBack callBack;
    
    public FundListViewAdapter(Context context,List<Map<String, Object>> fundList,CallBack callBack){ 
        this.mInflater = LayoutInflater.from(context);
        this.fundList = fundList;
        this.callBack = callBack;
    } 
    @Override
    public int getCount() { 
        return fundList==null?0:fundList.size(); 
    } 

    @Override
    public Object getItem(int arg0) { 
        return fundList.get(arg0); 
    } 

    @Override
    public long getItemId(int arg0) {
        return 0; 
    } 

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) { 
          
        ViewHolder holder = null; 
        if (convertView == null) { 
              
            holder=new ViewHolder();   
              
            convertView = mInflater.inflate(R.layout.fundlistpopup, null); 
            holder.seq = (TextView)convertView.findViewById(R.id.seq); 
            holder.img = (ImageView)convertView.findViewById(R.id.img); 
            holder.name = (TextView)convertView.findViewById(R.id.name); 
            convertView.setTag(holder); 
              
        }else { 
              
            holder = (ViewHolder)convertView.getTag(); 
        } 
          
          
        holder.seq.setText(String.valueOf(position+1)); 
        holder.img.setBackgroundResource((Integer)fundList.get(position).get("img")); 
        holder.name.setText((String)fundList.get(position).get("name")); 
          
        holder.img.setOnClickListener(new View.OnClickListener() { 
        	
            @Override
            public void onClick(View view) {
            	if(callBack!=null)
            	{
            		callBack.img_onClickFund(view,position);              
            	}
            } 
        }); 
          
          
        return convertView; 
    } 
	
    public class ViewHolder{ 
        public TextView seq; 
        public ImageView img; 
        public TextView name; 
    }
    
    public interface CallBack
    {
    	public void img_onClickFund(View view,int position);
    }
}
